home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gst0.10 / examples / cp.py < prev    next >
Encoding:
Python Source  |  2009-02-21  |  2.2 KB  |  83 lines

  1. #!/usr/bin/env python
  2. # -*- Mode: Python -*-
  3. # vi:si:et:sw=4:sts=4:ts=4
  4.  
  5. # gst-python
  6. # Copyright (C) 2002 David I. Lehn <dlehn@users.sourceforge.net>
  7. #               2004 Johan Dahlin  <johan@gnome.org>
  8. #
  9. # This library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Library General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2 of the License, or (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. # Library General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Library General Public
  20. # License along with this library; if not, write to the
  21. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. # Boston, MA 02111-1307, USA.
  23. # Author: David I. Lehn <dlehn@users.sourceforge.net>
  24. #
  25.  
  26. import sys
  27.  
  28. import gobject
  29. gobject.threads_init()
  30.  
  31. import pygst
  32. pygst.require('0.10')
  33. import gst
  34.  
  35.  
  36. mainloop = gobject.MainLoop()
  37.  
  38. def on_eos(bus, msg):
  39.    mainloop.quit()
  40.  
  41. def filter(input, output):
  42.    "A GStreamer copy pipeline which can add arbitrary filters"
  43.  
  44.    # create a new bin to hold the elements
  45.    bin = gst.parse_launch('filesrc name=source ! ' +
  46.                           # This 'statistics' element is depreciated in 0.10
  47.                           #'statistics silent=false buffer-update-freq=1 ' +
  48.                           #'update_on_eos=true ! ' +
  49.                           'filesink name=sink')
  50.    filesrc = bin.get_by_name('source')
  51.    filesrc.set_property('location', input)
  52.  
  53.    filesink = bin.get_by_name('sink')
  54.    filesink.set_property('location', output)
  55.  
  56.    bus = bin.get_bus()
  57.    bus.add_signal_watch()
  58.    bus.connect('message::eos', on_eos)
  59.  
  60.    # start playing
  61.    bin.set_state(gst.STATE_PLAYING)
  62.  
  63.    try:
  64.       mainloop.run()
  65.    except KeyboardInterrupt:
  66.       pass
  67.  
  68.    # stop the bin
  69.    bin.set_state(gst.STATE_NULL)
  70.  
  71. def main(args):
  72.    "A GStreamer based cp(1) with stats"
  73.  
  74.    if len(args) != 3:
  75.       print 'usage: %s source dest' % (sys.argv[0])
  76.       return -1
  77.  
  78.    return filter(args[1], args[2])
  79.  
  80. if __name__ == '__main__':
  81.    sys.exit(main(sys.argv))
  82.